import { onMounted, reactive, watchEffect } from 'vue'
import { getTopCategoryAPI } from '@/apis/category'
import { useRoute } from 'vue-router'
export function useGetCategoryList () {
  const route = useRoute()
  let categoryData = reactive({})
  const getCategory = async (id) => {
    const res = await getTopCategoryAPI(id)
    categoryData = Object.assign(categoryData, res.result)
  }
  watchEffect(() => {
    getCategory(route.params.id)
  })
  onMounted(() => {
    getCategory(route.params.id)
  })
  return { categoryData }
}